package com.dmzapp.cashoffer.util;

import java.io.File;
import java.util.Iterator;
import java.util.List;

import com.dmzapp.cashoffer.vo.UserAccount;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Environment;

public class AppManager {

    public static boolean isAppInstalled(Context paramContext, String packageName, List<PackageInfo> packageList) {

        Iterator<PackageInfo> localIterator = packageList.iterator();

        while (localIterator.hasNext()) {
            if (localIterator.next().packageName.equalsIgnoreCase(packageName))
                return true;
        }

        return false;
    }

    public static void InstallApplication(Context context, String apkName) {
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW);

        intent.setDataAndType(Uri.fromFile(new File(Environment.getExternalStorageDirectory() + "/fczapp/" + apkName)),
                "application/vnd.android.package-archive");

        context.startActivity(intent);
    }
    
    public static void openApp(String packageName, Context context) throws Exception {
		PackageManager localPackageManager = context.getPackageManager();
		Intent localIntent = localPackageManager
				.getLaunchIntentForPackage(packageName);

		localIntent.setAction("android.intent.action.VIEW");
		localIntent.addCategory("android.intent.category.DEFAULT");
		localIntent.putExtra("fcz_signal", Integer.valueOf(UserAccount.getInstance().getRest()));
		
		context.startActivity(localIntent);
        
    }
}
